﻿#ifndef _CREADWRITELOCK__H_
#define _CREADWRITELOCK__H_
//#include "kernel/OgreMemoryallocatedobject.h"

#include "kernel/Referenced.h"

namespace FD
{
	namespace Kernel
	{
		struct FD_READWRITELOCK_DATA;
		/// <summary>
		/// 读加锁
		/// </summary>
		class FD_Kernel_Export ReadWriteLock : public FD::Kernel::CReferenced
		{
		public:
			ReadWriteLock();

		public:
			virtual ~ReadWriteLock();
			/// <summary>
			/// 读写锁类
			/// </summary>
			/// <param name=""></param>
			/// <returns</returns>
			void lockForRead();
			/// <summary>
			/// 写加锁
			/// </summary>
			/// <param name=""></param>
			/// <returns</returns>
			void lockForWrite();
			/// <summary>
			/// 读解锁
			/// </summary>
			/// <param name=""></param>
			/// <returns</returns>
			void unlockForRead();
			/// <summary>
			/// 写解锁
			/// </summary>
			/// <param name=""></param>
			/// <returns</returns>
			void unlockForWrite();
		private:
			FD_READWRITELOCK_DATA *m_pData;
		};
		/// <summary>
		/// 自动读加锁、解锁类
		/// 构造的时候进行读加锁，析构的时候进行读解锁
		/// </summary>
		class FD_Kernel_Export ReadLocker : public FD::Kernel::CReferenced
		{
		public:
			ReadLocker(FD::Kernel::ReadWriteLock *pReadLocker);
			virtual ~ReadLocker();

		private:
			void _lock();
			void _unlock();
			FD::Kernel::ReadWriteLock *m_pLock;
		};
		/// <summary>
		/// 自动写加锁、解锁类
		/// 构造的时候进行写加锁，析构的时候进行写解锁
		/// </summary>
		class FD_Kernel_Export WriteLocker : public FD::Kernel::CReferenced
		{
		public:
			WriteLocker(FD::Kernel::ReadWriteLock *pWriteLocker);
			virtual ~WriteLocker();

		private:
			FD::Kernel::ReadWriteLock *m_pLock;
		};
	}
}

#endif

